package com.websuites.core.context;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.websuites.utils.LogUtil;

public class SpringBeanConnector {
	private static ApplicationContext context;

	public synchronized static Object getBean(String bean) {
		Object obj = null;
		try {
			if (SpringBeanConnector.context == null) {
				LogUtil.info("load spring configration now, spring-context*.xml path: "+ SpringBeanConnector.class.getClassLoader().getResource(".").getPath());
				System.out.println("load spring configration now, spring-context*.xml path: "+ SpringBeanConnector.class.getClassLoader().getResource(".").getPath());
				SpringBeanConnector.context = new ClassPathXmlApplicationContext("spring-context*.xml");
			}
			obj = context.getBean(bean);
		} catch (Exception ex) {
			ex.printStackTrace();
			LogUtil.error("bean " + bean + " can not be found!");
			obj = null;
		}
		return obj;
	}
	

}
